from django.template.loader import get_template
from django.template import Context
from django.template import RequestContext
from django.http import HttpResponse
from TrafficSimulator.MapInterface.Simulation.Simulation import SimConfig
from time import time
from MapInterface.models import TUser;

def hello(request):
	return HttpResponse("Hello world");

def Map(request):
	
	User = request.POST["Username"];
	Pass = request.POST["Password"];
	user = TUser.objects.filter(Username = User, Password = Pass)
	if (len(TUser.objects.filter(Username = User, Password = Pass))):
		id = str(time());
		t = get_template('Map.html');
		html = t.render(Context({'uniqId':id}));
		response = HttpResponse(html);
		response.set_cookie("UserId",user[0].id)
		return response;
	else:
		t = get_template('Login.html');
		c=RequestContext(request,{});
		html = t.render(c);
		return HttpResponse(html);

def Sim(request):

	formData = dict(request.GET);
	SimConfig(formData);
	return HttpResponse("a");

def Test(request):
	t = get_template('Tester.html');
	c= RequestContext(request,{});
	html = t.render(c);
	return HttpResponse(html);

def Login(request):
	t = get_template('Login.html');
	c=RequestContext(request,{});
	html = t.render(c);
	return HttpResponse(html);
# Create your views here.
